package com.wzy.webfluxclient;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class TestController {
    @Autowired
    private IUserApi userApi;

    @GetMapping("/")
    public void test() {

        //接口测试
//        userApi.getAllUser();
//        userApi.getUserById("2222222");
//        userApi.deleteUserById("111111111");
//        userApi.createUser(
//                Mono.just(User.builder().name("xfq").age(33).build()));
//        userApi.updateUserById("2222222", Mono.just(User.builder().name("xfq").age(33).build()));

        //查询全部用户
//        Flux<User> users = userApi.getAllUser();
//        users.subscribe(System.out::println);

        //根据id查询用户
        String id = "5ea5cc4861c01443a751c1a1";
        userApi.getUserById(id).subscribe(user -> {
            System.out.println("getById" + user);
        }, throwable -> {
            System.err.println("查找不到该用户" + throwable.getMessage());
        });

        String id2 = "5ea6a2c883e98a6ccd71a774";
        userApi.getUserById(id2).subscribe(user -> {
            System.out.println("getById" + user);
        }, throwable -> {
            System.err.println("查找不到该用户" + throwable.getMessage());
        });

        //删除用户
//        userApi.deleteUserById(id);

        //创建用户
        //    userApi.createUser(Mono.just(User.builder().name("tomy").age(22).build())).subscribe(System.out::println);
    }
}
